# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Simon Zeni <simon@bl4ckb0ne.ca>
pkgname=xwayland
pkgver=23.2.6
pkgrel=0
pkgdesc="Compact xserver to run under wayland for compatibility"
url="https://www.x.org/wiki"
arch="all"
license="MIT"
subpackages="$pkgname-dbg $pkgname-dev $pkgname-doc"
depends="xorg-server-common xkbcomp"
depends_dev="
	dbus-dev
	font-util-dev
	libdrm-dev
	libepoxy-dev
	libtirpc-dev
	libmd-dev
	libxcvt-dev
	libxfont2-dev
	libxkbfile-dev
	mesa-dev
	pixman-dev
	wayland-dev
	wayland-protocols
	xorgproto
	xtrans
	"
makedepends="
	$depends_dev
	meson
	"
source="https://xorg.freedesktop.org/archive/individual/xserver/xwayland-$pkgver.tar.xz
	use-libtirpc-nokrb.patch
	"

replaces="xorg-server-xwayland"

# secfixes:
#   23.2.5-r0:
#     - CVE-2024-31080
#     - CVE-2024-31081
#     - CVE-2024-31083
#   23.2.4-r0:
#     - CVE-2023-6816
#     - CVE-2024-0229
#     - CVE-2024-21885
#     - CVE-2024-21886
#     - CVE-2024-0408
#     - CVE-2024-0409
#   23.2.2-r0:
#     - CVE-2023-5367
#   22.1.8-r0:
#     - CVE-2023-0494
#   22.1.6-r0:
#     - CVE-2022-4283
#     - CVE-2022-46340
#     - CVE-2022-46341
#     - CVE-2022-46342
#     - CVE-2022-46343
#     - CVE-2022-46344
#   21.1.4-r0:
#     - CVE-2021-4008
#     - CVE-2021-4009
#     - CVE-2021-4010
#     - CVE-2021-4011
#   21.1.0-r4:
#     - CVE-2021-3472

build() {
	abuild-meson \
		-Db_lto=true \
		-Dipv6=true \
		-Dxvfb=false \
		-Dxdmcp=false \
		-Dxcsecurity=true \
		-Ddri3=true \
		-Dxwayland_eglstream=false \
		-Dglamor=true \
		-Dsha1=libmd \
		-Dxkb_dir=/usr/share/X11/xkb \
		-Dxkb_output_dir=/var/lib/xkb \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	# Part of xorg-server-doc
	rm -f "$pkgdir"/usr/share/man/man1/Xserver.1

	# Part of xorg-server-common
	rm -f "$pkgdir"/usr/lib/xorg/protocol.txt
}

sha512sums="
9e3c2253af335a559d0f890fa8f9bc381beca6531e0842d739ac15cbca008b3d07c0eefafd03611b04917c626861a7871a83657afa2a298994f4b162f714fc49  xwayland-23.2.6.tar.xz
42db6616a6566acedaa0c5dc125435183be0c0da5df4f542bf3857a1905ae4646d5eb311e4e00ec892c845a2dc2069f6e68f5f45ec6c499ea32b8e55d873a0f5  use-libtirpc-nokrb.patch
"
